-
Personally, I'd go with option 2 until such time that I could prove option 1 had much better (and needed) performance. If you choose option 1, make sure packet is a member of the struct.
Copying a few bytes (whether by memcpy or strcpy) is insignificant to the time it took to transmit those bytes over the net, or what other work you have planned later on.
> unsigned char storageArea[300]; //300 is an expected length
Or you could have a char pointer (as per case 1) then allocate the exact space you need, then copy the data.
-
Simply put, option 1 is a program logic and maintenance nightmare. You have three apparently independent members of the struct all pointing to the same memory area. It becomes very hard to keep track of who is responsible for freeing the memory, and when. It becomes even harder to find it out from the code after forgetting it. (Or the code is then maintained by someone else.)
So as Salem said, go with option 2 unless you really, really, REALLY need the performance of option 1.
-
Ty! That was the answer I needed :) Thx a lot
Krones